package cn.com.headfree.base.filter;

import cn.com.headfree.util.CookieUtil;
import com.gta.edu.sdk.util.StringUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@Component
@WebFilter(urlPatterns = "/human-manage-ding/*")
public class LoginFilter implements Filter {

    private static final Logger LOG = LogManager.getLogger(LoginFilter.class);

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        LOG.info("====================过滤器初始化=====================");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        HttpServletRequest hreq = (HttpServletRequest) request;
        String code = hreq.getParameter("code");
        LOG.info("===============拦截的code值为==============="+code);
        String path = ((HttpServletRequest) request).getRequestURI();
        LOG.info("==============path值为==============="+path);
        if(path.contains("dist") || path.contains("/fileDeal/download")|| path.contains("/isc/getUserInfoByTicket")){
            chain.doFilter(request, response);
        }else{
            LOG.info("===================应该拦截的接口===================="+path);
            /*String account = CookieUtil.getCookie(hreq,"account");
            if(!StringUtil.isNullOrEmpty(code) || !StringUtil.isNullOrEmpty(account)){
                chain.doFilter(request, response);
            }*/
            chain.doFilter(request, response);
        }
//        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {
    }

}
